{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#matplotlib inline\n",
    "def errCounter(res,standard):\n",
    "    errRate=0\n",
    "    for i in range(res.shape[0]):\n",
    "        if res[i]!=standard[i]:\n",
    "            errRate+=1\n",
    "            \n",
    "    return errRate/res.shape[0]\n",
    "\n",
    "\n",
    "print(\"www\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from basic import *\n",
    "from sklearn.model_selection import train_test_split\n",
    "# from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "from sklearn.neighbors import KNeighborsClassifier    #k近邻\n",
    "from sklearn.linear_model import LogisticRegression   #逻辑回归\n",
    "from sklearn.svm import SVC                         #支持向量机\n",
    "from sklearn.tree import DecisionTreeClassifier     #决策树\n",
    "from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier  #随机森林  #adaboost\n",
    "from sklearn.naive_bayes import GaussianNB          #朴素贝叶斯\n",
    "# from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis   #二次判别分析\n",
    "# from sklearn.neural_network import BernoulliRBM\n",
    "# from sklearn.gaussian_process import GaussianProcess\n",
    "\n",
    "\n",
    "\n",
    "classifiers = [\n",
    "    KNeighborsClassifier(3),\n",
    "    LogisticRegression(),\n",
    "    #SVC(kernel=\"linear\", C=0.025),\n",
    "    #SVC(gamma=2, C=1),\n",
    "    DecisionTreeClassifier(max_depth=5),\n",
    "    RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1),\n",
    "    AdaBoostClassifier(),\n",
    "    GaussianNB(),\n",
    "    #QuadraticDiscriminantAnalysis(),\n",
    "    #BernoulliRBM(),\n",
    "    #GaussianProcess(),\n",
    "]\n",
    "\n",
    "filename=\"pd_speech_features.csv\"\n",
    "\n",
    "feature,target,feature_name=file2fullMatrix(filename)\n",
    "feature=simplePCA(feature)\n",
    "\n",
    "\n",
    "x_train,x_test,y_train,y_test=train_test_split(feature,target,test_size=0.2)\n",
    "\n",
    "\n",
    "\n",
    "for func in classifiers:\n",
    "    func.fit(x_train,y_train)\n",
    "\n",
    "    \n",
    "print('hello')\n",
    "res=[i.predict(x_test) for i in classifiers]\n",
    "\n",
    "\n",
    "errRate=[errCounter(i,y_test) for i in res]\n",
    "print(\"w\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "names = [\"k近邻\", \"逻辑回归\", \"支持向量机1\",\"支持向量机2\"\n",
    "         \"决策树\", \"随机森林\", \"AdaBoost\",\n",
    "         \"朴素贝叶斯\", \"二次判别分析\"]\n",
    "\n",
    "\n",
    "print(errRate)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
